package com.fzy.designpattern.builder.impl2;

/**
 * 通过静态内部类实现复杂对象的无序构造。
 *
 * @author 冯赵杨
 * @create 2018/9/14
 */
public class PersonalInfo {
    private String name;
    private int age;
    private String gender;
    private String address;
    private String iDNumber;
    private String phoneNumber;

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public String getAddress() {
        return address;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getGender() {
        return gender;
    }

    public String getIDNumber() {
        return iDNumber;
    }

    public static class Builder {
        private String name;
        private int age;
        private String gender;
        private String address;
        private String iDNumber;
        private String phoneNumber;

        public Builder(String name) {
            this.name = name;
        }

        public Builder phoneNumber(String phoneNumber) {
            this.phoneNumber = phoneNumber;
            return this;
        }

        public Builder address(String address) {
            this.address = address;
            return this;
        }

        public Builder age(int age) {
            this.age = age;
            return this;
        }

        public Builder gender(String gender) {
            this.gender = gender;
            return this;
        }

        public Builder iDNumber(String iDNumber) {
            this.iDNumber = iDNumber;
            return this;
        }

        public PersonalInfo build() {
            return new PersonalInfo(this);
        }
    }

    private PersonalInfo(Builder builder) {
        this.address = builder.address;
        this.age = builder.age;
        this.gender = builder.gender;
        this.iDNumber = builder.iDNumber;
        this.name = builder.name;
        this.phoneNumber = builder.phoneNumber;
    }

}
